package com.xiyan.mocklocation.utils;


import java.util.HashMap;
import java.util.Objects;

/**
 * 操作消息提醒
 * 
 * @author wangjiao
 */
public class JsonResult extends HashMap<String, Object>
{
    private static final long serialVersionUID = 1L;

//    "data": {
//    "current": 0,
//            "serverIp0": "192.168,200.32",
//            "serverIp1": "192.168,200.35",
//            "serverIp2": "192.168,200.22",
//            "serverIp3": "192.168,200.92",
//            "serverPort0": "444",
//            "serverPort1": "444",
//            "serverPort2": "222",
//            "serverPort3": "444"
//},
//        "errorCode": 200,
//        "isSuccess": true

    public static final int errorCode_200 = 200;
    public static final int errorCode_201 = 201;
    /** 状态码 */
    public static final String CODE_TAG = "errorCode";

    /** 返回内容 */
    public static final String IS_SUCCESS_TAG = "isSuccess";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /**
     * 初始化一个新创建的 AjaxResult 对象
     * @param isSuccess
     * @param data
     */
    public JsonResult( Boolean isSuccess,Object data)
    {
        super.put(IS_SUCCESS_TAG, isSuccess);
        super.put(CODE_TAG, isSuccess?errorCode_200:errorCode_201);
        if (Objects.nonNull(data))
        {
            super.put(DATA_TAG, data);
        }
    }
    /**
     * 方便链式调用
     *
     * @param key
     * @param value
     * @return
     */
    @Override
    public JsonResult put(String key, Object value)
    {
        super.put(key, value);
        return this;
    }
    public static JsonResult success(Object data)
    {
        return new JsonResult( Boolean.TRUE, data);
    }
    public static JsonResult error()
    {
        return new JsonResult( Boolean.FALSE,null);
    }

}
